package com.core.dto;

import com.core.model.enumType.WorkOverTimeEnum;
import com.core.model.lxf.WorkOverTime;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * User: lxf
 * Date: 2017/2/17
 * Time: 14:38
 * To change this template use Editor | File and Code Templates.
 */
public class WorkOverTimeDTO {

    private String guid;
    private String startTime;
    private String endTime;
    private String workType;
    private String remark;

    private Map<String, Object> workTypeEnums = WorkOverTimeEnum.toMaps();

    public WorkOverTimeDTO() {

    }

    public WorkOverTimeDTO(String guid, String startTime, String endTime, String workType, String remark) {
        this.guid = guid;
        this.startTime = startTime;
        this.endTime = endTime;
        this.workType = workType;
        this.remark = remark;
    }

    public static WorkOverTimeDTO toDTO(WorkOverTime workOverTime) {
        return new WorkOverTimeDTO(workOverTime.guid(), workOverTime.startTime(), workOverTime.endTime(), workOverTime.workType().getLabel(), workOverTime.remark());
    }

    public static List<WorkOverTimeDTO> toDTOs(List<WorkOverTime> workOverTimes) {
        List<WorkOverTimeDTO> workOverTimeDTOs = new ArrayList<>();
        for (WorkOverTime workOverTime : workOverTimes) {
            workOverTimeDTOs.add(toDTO(workOverTime));
        }
        return workOverTimeDTOs;
    }

    public WorkOverTime toWorkOverTime(WorkOverTimeDTO workOverTimeDTO) {
        if (workOverTimeDTO.getStartTime().length() == 16) {
            workOverTimeDTO.setStartTime(workOverTimeDTO.getStartTime() + " 00");
        }
        if (workOverTimeDTO.getEndTime().length() == 16) {
            workOverTimeDTO.setEndTime(workOverTimeDTO.getEndTime() + " 00");
        }
        return new WorkOverTime(workOverTimeDTO.getStartTime(), workOverTimeDTO.getEndTime(), WorkOverTimeEnum.valueOf(workOverTimeDTO.getWorkType()), workOverTimeDTO.getRemark());
    }

    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getStartTime() {
        return startTime;
    }

    public void setStartTime(String startTime) {
        this.startTime = startTime;
    }

    public String getEndTime() {
        return endTime;
    }

    public void setEndTime(String endTime) {
        this.endTime = endTime;
    }

    public String getWorkType() {
        return workType;
    }

    public void setWorkType(String workType) {
        this.workType = workType;
    }

    public Map<String, Object> getWorkTypeEnums() {
        return workTypeEnums;
    }

    public void setWorkTypeEnums(Map<String, Object> workTypeEnums) {
        this.workTypeEnums = workTypeEnums;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }
}
